<?php
/**
 * Created by PhpStorm.
 * User: zhiqiang
 * Date Time: 2018/8/13 12:45
 */

namespace app\api\controller;


use JqStu\Clients\Ueditor;

class Upload
{
    private $upload;
    function _initialize()
    {
        parent::_initialize();

    }

    public function upfile()
    {
        $file = request()->file('file');
        $info = $file->move(ROOT_PATH . DS . 'uploads');
        if($info){
            $path = DS . 'uploads' . DS .$info->getSaveName();
            $path=str_replace("\\","/",$path);
            return json(array('code'=>200,'msg'=>'上传成功','path'=>$path,'size'=>$info->getSize(),'type'=>$info->getExtension(),'savename'=>$info->getSaveName(),'filename'=>$info->getFilename(),'info'=>$info->getInfo()));
        }else{
            return json(array('code'=>0,'msg'=>$file->getError()));
        }
    }

    public  function  ueditor(){
        $baidu=new Ueditor();
        $action = $_GET['action'];
        switch ($action){
            case "config":
                $result=$baidu->config();
                break;
            case  "uploadimage":
                $result=$baidu->uploadimage();
                break;
            case  "catchimage":
                $result=$baidu->catchimage();
                break;
            default:
                $result = array('state'=>'请求地址出错');
                break;
        }
        return  json($result);
    }
}